package 树.递归;

import java.util.*;

public class 二叉树中第二小的节点_671 {

    Set<Integer> set = new TreeSet<>();

    public int findSecondMinimumValue(TreeNode root) {
        if (root == null) {
            return -1;
        }

        traverseTree(root);
        int res = -1;
        if (set.size() > 0) {
            List<Integer> list = new ArrayList<>(set);
            if (set.size() >= 2) {
                res = list.get(1);
            }
        }

        return res;
    }


    public void traverseTree(TreeNode root) {
        if (root == null) {
            return;
        }

        set.add(root.val);
        traverseTree(root.left);
        traverseTree(root.right);

    }


}
